//
//  WLGP_GuideView.m
//  GuideInternalPurchase
//
//  Created by 王亮 on 2021/1/12.
//  Copyright © 2021 GuideInternalPurchase. All rights reserved.
//

#import "WLGP_GuideView.h"
#import "WLGP_PageCollectionViewCell.h"
#import "WLGP_PayCollectionViewCell.h"
#import "WLCollectionViewDelegate.h"

@interface WLGP_GuideView ()<WLCollectionDelegate,WLGP_PayViewDelegate>

@property(nonatomic,strong) WLCollectionViewDelegate *delegate_wl;
@property(nonatomic,strong) UICollectionView *collectionView;

@end
@implementation WLGP_GuideView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
        
        [self loadCollection];
    }
    return self;
}
#pragma mark -- 数据加载
-(void)loadCollection{
    self.delegate_wl.viewModel.viewLayer = [NSMutableArray array];
    
    CGFloat Width = [[UIScreen mainScreen] bounds].size.width;
    CGFloat Height = [[UIScreen mainScreen] bounds].size.height;
    {//page页
        WLBaseCollectionViewLayerSection *section = [WLBaseCollectionViewLayerSection new];
        section.type = @"section";
        {
            WLBaseCollectionViewLayerRow *row = [WLBaseCollectionViewLayerRow new];
            row.type = @"row";
            row.viewClass = WLGP_PageCollectionViewCell.class;
            WLGP_PageCollectionViewCellModel *model = [WLGP_PageCollectionViewCellModel new];
            model.bg_image_name = @"1234";
            
            row.data = model;
            row.cellSize = CGSizeMake(Width, Height);
            [section.item addObject:row];
        }
        [self.delegate_wl.viewModel.viewLayer addObject:section];
    }
    
    {//page页
        WLBaseCollectionViewLayerSection *section = [WLBaseCollectionViewLayerSection new];
        section.type = @"section";
        {
            WLBaseCollectionViewLayerRow *row = [WLBaseCollectionViewLayerRow new];
            row.type = @"row";
            row.viewClass = WLGP_PageCollectionViewCell.class;
            WLGP_PageCollectionViewCellModel *model = [WLGP_PageCollectionViewCellModel new];
            model.bg_image_name = @"1234";
            
            row.data = model;
            row.cellSize = CGSizeMake(Width, Height);
            [section.item addObject:row];
        }
        [self.delegate_wl.viewModel.viewLayer addObject:section];
    }
    
    {//支付页
        WLBaseCollectionViewLayerSection *section = [WLBaseCollectionViewLayerSection new];
        section.type = @"section";
        {
            WLBaseCollectionViewLayerRow *row = [WLBaseCollectionViewLayerRow new];
            row.type = @"row";
            row.viewClass = WLGP_PayCollectionViewCell.class;
            row.data = nil;
            row.cellSize = CGSizeMake(Width, Height);
            [section.item addObject:row];
        }
        [self.delegate_wl.viewModel.viewLayer addObject:section];
    }
}
#pragma mark -- WLGP_PayViewDelegate代理
/** 关闭控制器的动作 */
-(void)wl_closeViewType:(Guide_Close_Type)closeType{
    
}

#pragma mark -- 懒加载
-(UICollectionView *)collectionView{
    if(!_collectionView){
        UICollectionViewFlowLayout *Layout = [UICollectionViewFlowLayout new];
        [Layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
                _collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:Layout];
        _collectionView.backgroundColor = [UIColor clearColor];
        _collectionView.pagingEnabled = YES;
        _collectionView.bounces = NO;
        _collectionView.delegate = self.delegate_wl;
        _collectionView.dataSource = self.delegate_wl;
    }
    return _collectionView;
}
-(WLCollectionViewDelegate *)delegate_wl{
    if (!_delegate_wl){
        _delegate_wl = [[WLCollectionViewDelegate alloc]initWithDelegate:self];
    }
    return _delegate_wl;
}
@end
